Q*bert's Qubes
(c) 1984 Parker Brothers

Lockup Fix by Zinister

The cause: a race in the vblank wait

The game turns the VDP interrupt on (register 1 = $E2), but its NMI handler at $8021 is just RETN. It never reads the VDP status.

The frame wait at $8E58 reads the status (BIOS $1FDC) and then runs HALT until the next NMI.

The VDP's interrupt line stays active until someone reads the status, and the NMI only fires when that line changes. If vblank arrives in the ~14 cycles between the status read and the HALT, the NMI fires early and returns. Then HALT runs with the line still active, no new NMI ever arrives, and the CPU sleeps forever.

This can only happen on a frame where the game's work takes almost exactly one full frame. That's why early levels rarely freeze and busier later levels like Level 4 freeze more. It also fits the "random" pattern and the fact that it happens on both ColecoVision and ADAM. ColEm probably doesn't freeze because it handles the NMI more forgivingly than real hardware.

The fix

Both call $1FDC / HALT waits ($8E45 in the pause loop and $8E58 in the main loop) now call a new 10-byte routine at $BFF3, in unused padding at the end of the ROM.

The routine clears any pending vblank, just as the original did, then reads the VDP status in a loop until the frame bit is set. Because it doesn't depend on the NMI arriving, it can't hang.

Game timing is the same: it still waits for a fresh vblank every frame. No code anywhere uses the collision bits that the status reads clear.

